package UserView;

import Model.Student;
import ServiceImpl.StudentServiceImpl;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Scanner;

public class UserUi {

    private Connection connection;
    public static int id =1;
    public void UI() throws Exception {
        StudentServiceImpl studentService = new StudentServiceImpl();

        boolean flag = true;
        while (flag) {
            System.out.println("1.查询所有的学生信息");
            System.out.println("2.添加学生信息");
            System.out.println("3.删除学生信息");
            System.out.println("4.修改学生信息");
            System.out.println("5.查找学生信息");
            System.out.println("0.退出系统");
            Scanner scanner=null;
            int num=0;
            while (true){

                try {
                    System.out.println("亲，输入你所需要的业务序号");
                     scanner = new Scanner(System.in);
                     num = scanner.nextInt();
                     break;
                } catch (Exception e) {
                    System.out.println("请输入正确的业务数字");
                }
            }

            switch (num) {
                case 1:
                    studentService.showStu();
                    break;
                case 2:
                    System.out.println("请输入学生的姓名");
                    String name = scanner.next();
                    System.out.println("请输入学生的性别");
                    String sex = scanner.next();
                    System.out.println("请输入学生的年龄");
                    Integer age = scanner.nextInt();
                    System.out.println("请输入学生的专业");
                    String major = scanner.next();
                    Date date = new Date();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mmmm-dd hh:mm:ss");
                    String format = simpleDateFormat.format(date);
                    studentService.addStu(name,sex,age,major,format);

                    break;
                case 3:
                    System.out.println("请输入你要删除的学号");
                    int stuId = scanner.nextInt();
                    studentService.delStu(stuId);
                    break;
                case 4:
                    int a = 0;
                    System.out.println("请输入你要修改的学号");
                    int stuId1 = scanner.nextInt();
                    studentService.updateStu(stuId1);
                    System.out.println("修改成功");
                    break;
                case 5:
//                    System.out.println("请输入你要查找的学生学号 1-2");
//                    int numStu=scanner.nextInt();
//                    switch (numStu) {
//                        case 1:
//                            System.out.println("输入你查找的学号");
//                            int stuId2 = scanner.nextInt();
//                        boolean c = studentService.searchStu(stus, UserUi.num, stuId2);
//                        if (c) {
//                            System.out.println("查找成功");
//                        } else {
//                            System.out.println("查无此人");
//                        }
//                        break;
//                        case 2:
//                            studentService.findStu(stus,UserUi.num,find);
//                            if (UserUi.num1==0){
//                                System.out.println("查无此人");
//                            }else {
//                                System.out.println("您要查找的信息如下：");
//                                studentService.showStu(find,UserUi.num1);
//                            }
//                    }
//                    break;
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;
            }
        }
    }
}
